﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Scheduler.Data_Access_Layer
{
    /**Class: StaffingRequirements
    * @author Daniel Chopson
    * @version 1.0
    * Course : ITEC 4860 Spring 2012
    * Written: March 22, 2012
    *
    * This class connects to the OperatingDay, StaffingRequirements, and Company tables in the 
    * database via TableAdapters. Getters and setters are provided for all three.
    * Purpose: To provide the data access neccessary for modifying OperatingDay,
    * StaffingRequirements, and Company records in the Manager module.
    */

    class StaffingRequirements
    {
        //The day's ID

        private string dayID;

        //The company's ID

        private string companyID;

        //The adapter for OperatingDay table connectivity

        private SchedulerTableAdapters.OperatingDayTableAdapter operDayAdapter;

        //The data table for temporarily holding operating day data

        private Scheduler.OperatingDayDataTable operDayData;

        //A single row from the OperatingDay table

        private Scheduler.OperatingDayRow operDayRow;

        //The adapter for StaffingRequirements table connectivity

        private SchedulerTableAdapters.StaffingRequirementsTableAdapter staffReqAdapter;

        //The data table for temporarily holding staffing requirements data

        private Scheduler.StaffingRequirementsDataTable staffReqData;

        //A single row from the StaffingRequirements table
        
        private Scheduler.StaffingRequirementsRow staffReqRow;

        //The adapter for Company table connectivity

        private SchedulerTableAdapters.CompanyTableAdapter companyAdapter;

        //The data table for temporarily holding company data

        private Scheduler.CompanyDataTable companyData;

        //A single row from the companyRow table

        private Scheduler.CompanyRow companyRow;

        /** Method: StaffingRequirements
          * Constructor for this class. Instantiates all class variables
          * @param dayID the day's ID
          * @param companyID the company's ID
          */

        public StaffingRequirements(string dayID, string companyID)
        {
            this.dayID = dayID;
            this.companyID = companyID;
            operDayAdapter = new SchedulerTableAdapters.OperatingDayTableAdapter();
            staffReqAdapter = new SchedulerTableAdapters.StaffingRequirementsTableAdapter();
            companyAdapter = new SchedulerTableAdapters.CompanyTableAdapter();
        }

        /** Method: locateOperatingDay
          * Locates the row in the OperatingDay table with the specified day ID
          * Note: Must be called before the methods following it can be used
          * @return a boolean to denote whether the OperatingDay was found
          */

        public bool locateOperatingDay()
        {
            operDayData = operDayAdapter.GetDataByDayID(dayID);
            if (operDayData.Count == 0)
            {
                return false;
            }
            else
            {
                operDayRow = operDayData[0];
            }
            return true;
        }

        /** Method: getStartTime
          * Gets the operating day's start time
          * @return StartTime from the OperatingDay table
          */

        public TimeSpan getStartTime()
        {
            return operDayRow.StartTime;
        }

        /** Method: setStartTime
          * Sets the operating day's start time
          * @param startTime the operating day's start time
          */

        public void setStartTime(TimeSpan startTime)
        {
            operDayRow.StartTime = startTime;
            operDayAdapter.Update(operDayData);
        }

        /** Method: getEndTime
          * Gets the operating day's end time
          * @return EndTime from the OperatingDay table
          */

        public TimeSpan getEndTime()
        {
            return operDayRow.EndTime;
        }

        /** Method: setEndTime
          * Sets the operating day's end time
          * @param endTime the operating day's end time
          */

        public void setEndTime(TimeSpan endTime)
        {
            operDayRow.EndTime = endTime;
            operDayAdapter.Update(operDayData);
        }

        /** Method: getIsClosed
          * Gets the operating day's is closed flag
          * @return IsClosed from the OperatingDay table
          */

        public bool getIsClosed()
        {
            return operDayRow.IsClosed;
        }

        /** Method: setIsClosed
          * Sets the operating day's is closed flag
          * @param isClosed the operating day's is closed flag
          */

        public void setIsClosed(bool isClosed)
        {
            operDayRow.IsClosed = isClosed;
            operDayAdapter.Update(operDayData);
        }

        /** Method: getTimeChanged
        * Gets the operating day's TimeChanged Value
        * @return TimeChanged from the OperatingDay table
        */

        public string getTimeChanged()
        {
            return operDayRow.TimeChanged;
        }

        /** Method: setTimeChanged
          * Sets the operating day's TimeChanged value
          * @param TimeChanged is when the fields were last saved
          */

        public void setTimeChanged(string timeChanged)
        {
            operDayRow.TimeChanged = timeChanged;
            operDayAdapter.Update(operDayData);
        }


        /** Method: locateStaffingRequirements
          * Locates the row in the StaffingRequirements table with the specified day ID
          * Note: Must be called before the methods following it can be used
          * @return a boolean to denote whether the StaffingRequirements was found
          */

        public bool locateStaffingRequirements()
        {
            staffReqData = staffReqAdapter.GetDataByDayID(dayID);
            if (staffReqData.Count == 0)
            {
                return false;
            }
            else
            {
                staffReqRow = staffReqData[0];
            }
            return true;
        }

        /** Method: getAllPerHr
          * Gets all of the fields for a given row
          * @return an Array of database fields
          */

        public Array getAllPerHr()
        {
            return staffReqRow.ItemArray;
        }

        /** Method: setAllPerHr
          * Sets all of the fields for a given row
          * @param perHrArray an Array of all fields to be saved to the database
          */

        public void setAllPerHr(Array perHrArray)
        {
            staffReqRow.ItemArray = (object[])perHrArray;
            staffReqAdapter.Update(staffReqData);
        }

        /** Method: locateCompany
          * Locates the row in the Company table with the specified company ID
          * Note: Must be called before the methods following it can be used
          * @return a boolean to denote whether the Company was found
          */

        public bool locateCompany()
        {
            companyData = companyAdapter.GetDataByCompanyID(companyID);
            if (companyData.Count == 0)
            {
                return false;
            }
            else
            {
                companyRow = companyData[0];
            }
            return true;
        }

        /** Method: getMaxWeeklyPayroll
          * Gets the maximum weekly payroll
          * @return MaxWeeklyPayroll from the Company table
          */

        public Decimal getMaxWeeklyPayroll()
        {
            return companyRow.MaxWeeklyPayroll;
        }

        /** Method: setMaxWeeklyPayroll
          * Sets the maximum weekly payroll
          * @param maxWeeklyPayroll the maximum weekly payroll
          */

        public void setMaxWeeklyPayroll(Decimal maxWeeklyPayroll)
        {
            companyRow.MaxWeeklyPayroll = maxWeeklyPayroll;
            companyAdapter.Update(companyData);
        }
    }
}
